<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <%@taglib prefix="import" uri="/WEB-INF/tld/importTag.tld" %>
<%@taglib prefix="pu" uri="/WEB-INF/tld/pageutil.tld" %>
<%@taglib prefix="mu" uri="/WEB-INF/tld/mallutil.tld" %>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<import:around enableCache="false" url="qaa/product?memberId=${mu:memberId()}" appendParameter="memberId,answered">
<script>
$(function(){

	if('${param.answered}'=='true'){
	    $('#current_location').html(' > 商品问答 - 已回答');
	    $("#m_product_answered").css("font-weight","bold");
	}else{
		$('#current_location').html(' > 商品问答 - 发问中');
		$("#m_product_asked").css("font-weight","bold");
	}
});
</script>
<c-rt:set var="orderByName" value="desc"/>
<c-rt:if test="${!empty param.orderByName}">
	<c-rt:set var="orderByName" value="${param.orderByName}"/>
</c-rt:if>
<c-rt:set var="orderByAnswerDate" value="desc"/>
<c-rt:if test="${!empty param.orderByAnswerDate}">
	<c-rt:set var="orderByAnswerDate" value="${param.orderByAnswerDate}"/>
</c-rt:if>
<c-rt:set var="orderByQuestionDate" value="desc"/>
<c-rt:if test="${!empty param.orderByQuestionDate}">
	<c-rt:set var="orderByQuestionDate" value="${param.orderByQuestionDate}"/>
</c-rt:if>
<c-rt:if test="${param.orderByName=='desc' or orderByName == 'desc'}">
	<c-rt:set var="nextOrderByName" value="asc"/>
</c-rt:if>

<c-rt:if test="${param.orderByName=='asc' or orderByName == 'asc'}">
	<c-rt:set var="nextOrderByName" value="desc"/>
</c-rt:if>
<c-rt:if test="${param.orderByQuestionDate=='desc' or orderByQuestionDate == 'desc'}">
	<c-rt:set var="nextOrderByQuestionDate" value="asc"/>
</c-rt:if>
<c-rt:if test="${param.orderByQuestionDate=='asc' or orderByQuestionDate == 'asc'}">
	<c-rt:set var="nextOrderByQuestionDate" value="desc"/>
</c-rt:if>
<c-rt:if test="${param.orderByAnswerDate=='asc' or orderByAnswerDate == 'asc'}">
	<c-rt:set var="nextOrderByAnswerDate" value="desc"/>
</c-rt:if>
<c-rt:if test="${param.orderByAnswerDate=='desc' or orderByAnswerDate == 'desc'}">
	<c-rt:set var="nextOrderByAnswerDate" value="asc"/>
</c-rt:if>
<c-rt:if test="${param.orderByQuestionDate=='desc' or orderByQuestionDate == 'desc'}">
	<c-rt:set var="nextOrderByQuestionDate" value="asc"/>
</c-rt:if>
<c-rt:choose>
<c-rt:when test="${(empty param.orderByName && empty param.orderByQuestionDate) || !empty param.orderByAnswerDate}">
<c-rt:set var="orderHql">
order by q.answeredDate ${orderByAnswerDate }
</c-rt:set>
</c-rt:when>
<c-rt:when test="${(!empty param.orderByQuestionDate)}">
<c-rt:set var="orderHql">
order by q.createDate ${orderByQuestionDate }
</c-rt:set>
</c-rt:when>

<c-rt:otherwise>
<c-rt:set var="orderHql">
order by q.extraValue['productId'].value ${orderByName }
</c-rt:set>
</c-rt:otherwise>
</c-rt:choose>

<c-rt:set var="aHql">
from Question q where q.memberId=? and q.extraValue['isProductQAA'].value=? and q.extraValue['productId'].value!=null and q.answer!=null ${orderHql }
</c-rt:set>

${pu:listAdd('params', mu:memberId()) }
${pu:listAdd('params', 'true') }
${pu:reqSet('questionCount', pu:countByHql(aHql, pu:arrayGet('params'))) }
<c-rt:set var="bHql">
from Question q where q.memberId=? and q.extraValue['isProductQAA'].value=? and q.extraValue['productId'].value!=null and q.answer=null ${orderHql}
</c-rt:set>
${pu:reqSet('questionCount2', pu:countByHql(bHql, pu:arrayGet('params'))) }
<c-rt:if test="${param.answered=='true'}">
${pu:reqSet('questions', pu:queryByHql(aHql, pu:arrayGet('params'), null)) }
</c-rt:if>
<c-rt:if test="${param.answered=='false'}">
${pu:reqSet('questions', pu:queryByHql(bHql, pu:arrayGet('params'), null)) }
</c-rt:if>


<!-- content start --> 
  <div class="content mb-od"> 
    <!-- 我的訂單 --> 
    <h2>商品问答</h2> 
    <div class="mb-show"> 
      <ul class="mb-tab"> 
        <li <c-rt:if test="${param.answered=='true' }">class="mb-tab-f"</c-rt:if>><a href="<c-rt:url value="/member/product/qaa.do?answered=true&orderByAnswerDate=desc"/>">已回答(<b>${questionCount }</b>)</a></li> 
        <li <c-rt:if test="${param.answered=='false' }">class="mb-tab-f"</c-rt:if>><a href="<c-rt:url value="/member/product/qaa.do?answered=false&orderByQuestionDate=desc"/>">发问中(<b>${questionCount2 }</b>)</a></li> 
      </ul> 
      <p>• 本页显示您在商品页提问后，已被商家回复的问题。此页仅保存 3 个月内的纪录。</p> 
     </div> <table class="tb-2-pd"> 
        <thead> 
          <tr> 
          	<c-rt:choose>
            <c-rt:when test="${param.answered == 'true'}">
	            <th width="10%">商品图片</th> 
	            <th width="20%">
	            	<span <c-rt:if test="${param.orderByName=='asc' }">class="toselect-up"</c-rt:if><c-rt:if test="${param.orderByName=='desc' }">class="toselect-down"</c-rt:if>>
	            	<a href="<c-rt:url value="/member/product/qaa.do?answered=${param.answered }&orderByName=${nextOrderByName }"/>">商品名称</a>
	            	</span>
	            </th> 
	            <th width="29%">我的问题</th> 
	           	<th width="30%">商家回答</th> 
	            <th width="11%">
	            	<span <c-rt:if test="${param.orderByAnswerDate=='asc' }">class="toselect-up"</c-rt:if><c-rt:if test="${param.orderByAnswerDate=='desc' }">class="toselect-down"</c-rt:if>>
	            	<a href="<c-rt:url value="/member/product/qaa.do?answered=${param.answered }&orderByAnswerDate=${nextOrderByAnswerDate }"/>">回答时间</a>
	            	</span>
	            </th>
            </c-rt:when>
            <c-rt:when test="${param.answered == 'false'}">
	            <th width="10%">商品图片</th> 
	            <th width="20%">
	            	<span <c-rt:if test="${param.orderByName=='asc' }">class="toselect-up"</c-rt:if><c-rt:if test="${param.orderByName=='desc' }">class="toselect-down"</c-rt:if>>
	            	<a href="<c-rt:url value="/member/product/qaa.do?answered=${param.answered }&orderByName=${nextOrderByName }"/>">商品名称</a>
	            	</span>
	            </th> 
	            <th width="29%">我的问题</th> 
	            <th width="11%">
	            	<span <c-rt:if test="${param.orderByQuestionDate=='asc' }">class="toselect-up"</c-rt:if><c-rt:if test="${param.orderByQuestionDate=='desc' }">class="toselect-down"</c-rt:if>>
	            	<a href="<c-rt:url value="/member/product/qaa.do?answered=${param.answered }&orderByQuestionDate=${nextOrderByQuestionDate }"/>">发问时间</a>
	            	</span>
	            </th>
            </c-rt:when>   
            </c-rt:choose>          
          </tr> 
        </thead> 
        <tbody> 
        <c-rt:if test="${!empty questions}">
       	<c-rt:forEach items="${questions}" var="question" varStatus="status">
       	<c-rt:set var="product" value="${pu:get('com.yaodian100.ec.product.entity.Product', question.extraValue['productId'].value)}"/>
       	  <c-rt:forEach items="${question.answers }" var="answer" varStatus="aStatus">
       	  <c-rt:set var="answerCount" value="${aStatus.index+1 }"/>
       	  </c-rt:forEach>
       	  <c-rt:if test="${!empty question.answers}">
       	  <c-rt:forEach items="${question.answers}" var="answer" varStatus="aStatus">
          <tr>
          	<c-rt:if test="${aStatus.index==0}">
            <td rowspan="${answerCount }" valign="top" class="pic-center"><a href="<c-rt:url value="/product/product.do?productId=${question.extraValue['productId'].value }"/>"><img src="/PImg/${pu:substring(question.extraValue['productId'].value, 0,4) }/${question.extraValue['productId'].value }/${question.extraValue['productId'].value }_m100.jpg" alt="" width="50" height="50" onError="this.src='/PImg/blank_100.gif'"/></a></td> 
            <td rowspan="${answerCount }" valign="top"><p><a href="<c-rt:url value="/product/product.do?productId=${question.extraValue['productId'].value }"/>">${product.productName }</a></p></td> 
            <td rowspan="${answerCount }" valign="top"><p>${question.description }</p></td> 
            </c-rt:if>

            <c-rt:if test="${param.answered == 'true'}">
            <td valign="top">
            <c-rt:if test="${answer.isApproved!=false}">
            <p>
            <c-rt:if test="${answer.showOnProductPage}">
            <a href="<c-rt:url value="/product/product.do?productId=${question.extraValue['productId'].value }#productqaa"/>">${pu:substring(answer.content, 0, 40) }</a>
			</c-rt:if>
			<c-rt:if test="${!answer.showOnProductPage}">
			<a href="<c-rt:url value="/product/product.do?productId=${question.extraValue['productId'].value }#productqaa"/>">${answer.content }</a>
			</c-rt:if>
			</p>
			<c-rt:if test="${!answer.showOnProductPage}">
			<p class="bg-yl txt-gy">此笔问与答商家設為隱藏，將不顯示於商品页中。</p>
			</c-rt:if>
			</c-rt:if>
			 <c-rt:if test="${answer.isApproved==false}">
			 <p>正在回复中</p>
			 </c-rt:if>
			</td> 
            
            </c-rt:if>
            <td valign="top" class="txt-date"><p><fmt-rt:formatDate value="${answer.createDate}" pattern="yyyy-MM-dd"/><br/><fmt-rt:formatDate value="${answer.createDate}" pattern="HH:mm:ss"/></p></td> 
          </tr> 
          </c-rt:forEach>
          </c-rt:if>
          <c-rt:if test="${empty question.answers}">
          <tr> 
            <td valign="top" class="pic-center"><a href="<c-rt:url value="/product/product.do?productId=${question.extraValue['productId'].value }"/>"><img src="/PImg/${pu:substring(question.extraValue['productId'].value, 0,4) }/${question.extraValue['productId'].value }/${question.extraValue['productId'].value }_m100.jpg" alt="" width="50" height="50" onError="this.src='/PImg/blank_100.gif'"/></a></td> 
            <td valign="top"><p><a href="<c-rt:url value="/product/product.do?productId=${question.extraValue['productId'].value }"/>">${product.productName }</a></p></td> 
            <td valign="top"><p>${question.description }</p></td> 
            <td valign="top" class="txt-date"><p><fmt-rt:formatDate value="${question.createDate}" pattern="yyyy-MM-dd"/><br/><fmt-rt:formatDate value="${question.createDate}" pattern="HH:mm:ss"/></p></td> 
          </tr>
          </c-rt:if>
          </c-rt:forEach>
        </c-rt:if>  
				<c-rt:if test="${empty questions}">
          <tr>
            <td colspan="5" class="norecord">您没有任何记录。</td>
          </tr>
        </c-rt:if>
        </tbody> 
      </table> 
      <p>&nbsp;</p> 
      <table class="tb-2-pd"> 
        <tbody> 
          <tr> </tr> 
        </tbody> 
      </table> 
    </div> 
  <!-- content end --> 
  </import:around>